// pages/orderList/orderList.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _token : '',
    imgpath :'',

    currentTab:0,

    orderJson:'',
    orderlist:[],//列表
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var _key = wx.getStorageSync("token");
    var _imgpath = app.globalData.imgsPath;
    var _cur = that.data.currentTab;
    
    that.setData({
      _token: _key,
      imgpath: _imgpath
    })
    wx.showLoading({
      title: '数据加载中',
    })

    if(options.status) {
      _cur = options.status;
      that.setData({
        currentTab: _cur,
      })
    }
    that.getOrderList(_cur);
  },
  //获取订单列表
  getOrderList: function (statusNum){
    var that = this;
    var _key = that.data._token;
    wx.request({
      url: app.globalData.httpsPath + '/order/list',
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      data: {
        token: _key,
        status: statusNum
      },
      //请求后台数据成功  
      success: function (res) {
        
        var orderObj = res.data.data;
        var orderList = res.data.data.data;
        console.info(orderList);
        that.setData({
          orderJson: orderObj,
          orderlist: orderList
        })
        // 隐藏加载框
        wx.hideLoading();
      }
    })
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.currentTarget.dataset.typeid) {
      return false;
    } else {
      that.setData({
        currentTab: e.currentTarget.dataset.typeid,
      })
      wx.showLoading({
        title: '数据加载中',
      })
      //获取订单列表
      that.getOrderList(e.currentTarget.dataset.typeid);
    }
  },
})